home *** CD-ROM | disk | FTP | other *** search
- /* Filelist.c -- Public Domain -- By Erik Vanriper -- SoWhutWare 1991
- **
- ** Why? Because I had nothing better to do.
- **
- ** I probably could have done this 10 other ways, but I figured this works,
- ** so why break it. The only thing left to add is the wildcard expansion
- ** on files. Maybe tomorrow.....
- **
- ** I used Turbo C++ 1.0 on this, hack it to your hearts desire.
- **
- ** If you use a function, please give credit, I know I did.
- **
- ** If the code format looks wierd, I used a tab stop of 3, and QEdit.
- **
- */
-
- /*------------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <alloc.h>
- #include <dir.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <time.h>
- #include <process.h>
- #include <dos.h>
-
- void bios_open(void);
- void bios_scroll_dn(int,int,int,int,int);
- void bios_scroll_up(int,int,int,int,int);
- void bios_move(int,int);
- void vtest(void);
- void files(int);
- void mainscreen();
- void message(char *);
- void print_atcolor(int, int, int, unsigned char *);
- void areap(char *);
- void aread(char *);
-
- #define cls() bios_scroll_dn(25,0,0,24,79); bios_move(0,0);
- #define NUL '\0' /* This is part of Bob Stouts "commafmt()" code */
- #define B_BLACK 0
- #define B_BLUE 16
- #define B_GREEN 32
- #define B_CYAN 48
- #define B_RED 64
- #define B_MAGENTA 80
- #define B_BROWN 96
- #define B_GRAY 112
- #define F_BLACK 0
- #define F_BLUE 1
- #define F_GREEN 2
- #define F_CYAN 3
- #define F_RED 4
- #define F_MAGENTA 5
- #define F_BROWN 6
- #define F_GRAY 7
- #define F_LBLACK 8
- #define F_LBLUE 9
- #define F_LGREEN 10
- #define F_LCYAN 11
- #define F_LRED 12
- #define F_LMAGENTA 13
- #define F_YELLOW 14
- #define F_WHITE 15
-
- struct xx
- {
- char FilePath[70]; /* 69 chars for the path */
- char AreaDesc[76]; /* 75 chars for the description. */
- };
-
- struct xx *path[200]; /* Max of 200 areas to malloc() 29,200 bytes. */
- struct stat info;
- struct tm *tmfile;
- struct ffblk fileinfo;
- time_t tnow;
-
- char drive[MAXDRIVE];
- char dir[MAXDIR];
- char filename[MAXFILE];
- char ext[MAXEXT];
- char filepath[MAXPATH];
-
- int tempcount = 0;
- int start = 0;
- int new = 0;
- int numfiles[200];
- long numbytes, areabytes;
-
- char descrip[165], keeppath[70];
- char *whitespace = " \t\n\r";
- char input[80] = "FILELIST.CFG"; /* Default config file */
- char systemname[80];
- int days;
-
- char cga, ega, vga, mcga, mono, herc, none, color_disp, b_w;
- unsigned char cur_attr;
- int cur_mode, cur_page;
-
- FILE *outfile, *newfile;
-
- /*------------------------------------------------------------------------------*/
-
- main(int argc, char *argv[])
- {
- FILE *fp;
- /*char tempbuff[100];*/
- int t;
- numbytes = areabytes = 0;
-
- time(&tnow);
- bios_open();
-
- for(t=0; t < 200; t++)
- {
- if((path[t] = malloc(sizeof(struct xx))) == NULL)
- {
- puts("not enough memory! aborting...");
- exit(255);
- }
- }
-
- mainscreen();
-
- if(argc > 1) /* assume that argv[1] is a valid config file */
- {
- strcpy(input, argv[1]);
- sprintf(descrip,"Using configuration file %s",input);
- areap(descrip);
- }
-
- parsectl(); /* parse the control file */
-
- /* Normalize the first two paths for reading and writing */
- fnsplit(path[0]->FilePath, drive, dir, filename, ext);
- fnmerge(path[0]->FilePath, drive, dir, filename, ext);
- fnsplit(path[1]->FilePath, drive, dir, filename, ext);
- fnmerge(path[1]->FilePath, drive, dir, filename, ext);
- fnsplit(path[2]->FilePath, drive, dir, filename, ext);
- fnmerge(path[2]->FilePath, drive, dir, filename, ext);
-
- if((outfile = fopen(path[1]->FilePath, "wt")) == NULL) /* open output file */
- {
- printf("Error opening %s",path[1]->FilePath);
- exit(255);
- }
-
- if((fp = fopen(path[2]->FilePath, "rt")) == NULL) /* open header file */
- {
- printf("Error opening %s",path[2]->FilePath);
- exit(255);
- }
-
- if((newfile = fopen(path[0]->FilePath, "wt")) == NULL) /* open newfiles file */
- {
- printf("Error opening %s",path[0]->FilePath);
- exit(255);
- }
-
- aread("Welcome to FileList!");
-
- tmfile = localtime(&tnow);
-
- fprintf(outfile,"Report Started: %s\n",asctime(tmfile));
- while(fgets(descrip,164,fp) != NULL) /* write header file line by line */
- fputs(descrip,outfile);
-
- fclose(fp); /* Close header file */
- fprintf(newfile,"Report Created: %s\n",asctime(tmfile));
- fprintf(newfile,"Latest files to arrive at %sduring the last %d days:\n",systemname,days);
- listfiles(); /* process each FILES.BBS */
-
- for(t=0;t<200;t++) free(path[t]); /* free the memory */
- fclose(outfile); /* close the output file */
- fclose(newfile); /* close the output file */
- bios_move(23,1); /* put cursor at bottom of screen */
- return(1); /* all done */
- }
-
- /*------------------------------------------------------------------------------*/
-
- /*
- ** commafmt()
- **
- ** Public domain by Bob Stout
- **
- ** Notes: 1. Use static buffer to eliminate error checks on buffer overflow
- ** and reduce code size.
- ** 2. By making the numeric argument a long and prototyping it before
- ** use, passed numeric arguments will be implicitly cast to longs
- ** thereby avoiding int overflow.
- ** 3. Use the thousands grouping and thousands separator from the
- ** ANSI locale to make this more robust.
- */
-
-
-
- /* Buffer for formatted string */
- /* Size of buffer */
- /* Number to convert */
-
- commafmt(char *buf, int bufsize, long N)
- /*size_t commafmt(char *buf, int bufsize, long N)*/
- {
- int len = 1, posn = 1, sign = 1;
- char *ptr = buf + bufsize - 1;
-
- if (2 > bufsize)
- {
- ABORT: *buf = NUL;
- return 0;
- }
-
- *ptr-- = NUL;
- --bufsize;
- if (0L > N)
- {
- sign = -1;
- N = -N;
- }
-
- for ( ; len <= bufsize; ++len, ++posn)
- {
- *ptr-- = (char)((N % 10L) + '0');
- if (0L == (N /= 10L))
- break;
-
- if (0 == (posn % 3))
- {
- *ptr-- = ',';
- ++len;
- }
-
- if (len >= bufsize) goto ABORT;
- }
-
- if (0 > sign)
- {
- if (0 == bufsize) goto ABORT;
- *ptr-- = '-';
- }
-
- strcpy(buf, ++ptr);
- return (size_t)len;
- }
-
- /*------------------------------------------------------------------------------*/
-
- int listfiles()
- {
- FILE *fp;
- static int i, j, count, test = 0, test2 = 0;
- char desc[200];
- char buf[20];
- char mytemp[80];
-
- sprintf(mytemp,"Output File: %s",path[1]->FilePath);
- areap(mytemp);
- sprintf(mytemp,"New Files Output File: %s for %d days",path[0]->FilePath,days);
- areap(mytemp);
- for(i=3;i<start;i++)
- {
- test = strlen(path[i]->FilePath);
- sprintf(mytemp,"%s",path[i]->FilePath);
- mytemp[test - 1] = '\0';
- aread(mytemp);
- strcpy(keeppath,path[i]->FilePath);
- strcat(path[i]->FilePath,"files.bbs");
-
- if((fp = fopen(path[i]->FilePath,"rt")) == NULL)
- {
- continue;
- }
- strcpy(mytemp,path[i]->AreaDesc);
- mytemp[(strlen(path[i]->AreaDesc) - 1)] = '\0';
- fprintf(outfile,"\n▓▒░%s ░▒▓\n",mytemp);
- fprintf(newfile,"\n\n▓▒░%s ░▒▓\n",mytemp);
-
- test2 = strlen(path[i]->AreaDesc);
-
- sprintf(mytemp,"%d ",i-2);
- test2 += strlen(mytemp);
- strcat(mytemp,path[i]->AreaDesc);
- mytemp[test2-1] = '\0';
- areap(mytemp);
-
- count = areabytes = 0;
-
- while(fgets(desc,200,fp) != NULL)
- if(processline(desc)) count++;
-
- numfiles[i] = count;
- tempcount += count;
-
- if(count)
- {
- commafmt(buf,20,areabytes);
- fprintf(outfile,"\n\n=-= Area Stats: %s Bytes in %d Files\n",buf,count);
- files(tempcount);
- commafmt(buf,20,numbytes);
- print_atcolor(22,5,B_BLUE+F_YELLOW,buf);
- }
- else
- {
- fprintf(outfile,"\n\n=-= Area Stats: NO FILES\n");
- }
- for(j = 0; j < 72; j++)
- fprintf(outfile,"*");
-
- fclose(fp);
- }
-
- count = 0;
-
- message("Computing Statistics...");
-
- fprintf(outfile,"\n\n=-=-=-=-=-=-=\nFinal Report:\n=-=-=-=-=-=-=\n");
- sprintf(mytemp,"=-=-=-=-=-=-= Final Report =-=-=-=-=-=-=");
- areap(mytemp);
-
- for(i=3;i<start;i++)
- {
- fprintf(outfile," %3d Files in%s",numfiles[i],path[i]->AreaDesc);
- count += numfiles[i];
- }
-
- commafmt(buf,20,numbytes);
-
- sprintf(mytemp,"%4d Total Files in %s bytes",count, buf);
- fprintf(outfile," ----\n %s",mytemp);
- areap(mytemp);
- time(&tnow);
- tmfile = localtime(&tnow);
- fprintf(outfile,"\n\nReport Finished : %s",asctime(tmfile));
- sprintf(mytemp,"* Produced automatically by FILELIST (1991) Erik Vanriper. (1:107/230) *\n");
- fprintf(outfile,mytemp);
- fprintf(newfile,"\n%s",mytemp);
- fprintf(newfile,"\nPress Enter To Continue: ");
- message("Thank you for using FILELIST!");
- return(1);
- }
-
- /*------------------------------------------------------------------------------*/
-
- void killspace(char *buffer)
- {
- int test;
-
- test = strspn(buffer,whitespace);
- strcpy(descrip,(buffer + test));
- }
-
- /*------------------------------------------------------------------------------*/
-
- int processline(char *desc)
- {
- char filename[13], *test, check[80];
- int result, c, i, d;
-
- if((desc[0] < '\x30') || (desc[0] > '\x7A') || ((desc[0] > '\x3A') && (desc[0] < '\x41')) || ((desc[0] > '\x5A') && (desc[0] < '\x61')))
- {
- fputs(desc,outfile);
- return(0);
- }
-
- test = strtok(desc," ");
- strcpy(filename,test);
- test = strtok(NULL,"\r\n");
- strcpy(descrip,test);
-
- strcpy(check,keeppath);
- strcat(check,"\\");
- strcat(check,filename);
-
- killspace(descrip);
-
- if(stat(check, &info) !=0) return(0);
-
- numbytes += info.st_size;
- areabytes += info.st_size;
-
- tmfile = localtime(&info.st_atime);
-
- fprintf(outfile,"\n%-13s%6ld %.2d-%.2d-%d",filename,info.st_size,
- (tmfile->tm_mon +1),tmfile->tm_mday,tmfile->tm_year);
-
- if((tnow - info.st_atime) < (long)((long)days * 86400L))
- {
- fprintf(newfile,"\n%-13s%6ld %.2d-%.2d-%d ",filename,info.st_size,
- (tmfile->tm_mon +1),tmfile->tm_mday,tmfile->tm_year);
- new = 1;
- }
-
- fprintf(outfile,((tnow - info.st_atime) < 2678400L) ? "* " : " ");
-
- writedescrip();
-
- return(1);
- }
-
- /*------------------------------------------------------------------------------*/
-
- writedescrip()
- {
- char *token;
- int test, x = 0;
-
- test = strlen(descrip);
- if(!test)
- {
- /*fprintf(outfile,"\n");*/
- if(new) fprintf(newfile,"\n");
- new = 0;
- return(0);
- }
- if(test <= 47)
- {
- fprintf(outfile,"%s",descrip);
- if(new) fprintf(newfile,"%s",descrip);
- new = 0;
- return(1);
- }
- else
- {
- token = strtok(descrip,whitespace);
-
- while(token != NULL)
- {
- x = x + strlen(token);
-
- if(x <= 47)
- {
- fprintf(outfile,"%s ",token);
- if(new) fprintf(newfile,"%s ",token);
- x = x + 1;
- }
-
- else
- {
- x = 1;
- fprintf(outfile,"\n %s ",token);
- if(new) fprintf(newfile,"\n %s ",token);
- }
-
- token = strtok(NULL,whitespace);
- }
- }
- /*fprintf(outfile,"\n");*/
- /*if(new) fprintf(newfile,"\n");*/
- new = 0;
- return(1);
- }
-
- /*------------------------------------------------------------------------------*/
-
- int parsectl()
- {
- FILE *fp;
- int result, c, i, d;
- char wholeline[200], *test;
-
- if ((fp = fopen(input,"rt")) == NULL)
- {
- cls();
- printf("Can't find file %s",input);
- exit(255);
- }
-
- message("Parsing configuration file...");
-
- fgets(wholeline,200,fp); /* Get system name */
- strcpy(systemname,wholeline);
- fgets(wholeline,200,fp); /* Get NEWFILES days */
- days = atoi(wholeline);
-
- c = 0;
- while(fgets(wholeline,200,fp) != NULL)
- {
- test = strstr(wholeline, "\x20");
-
- if(test == NULL)
- {
- strcpy(path[c]->FilePath,wholeline);
- d = strlen(path[c]->FilePath);
- path[c]->FilePath[d] = '\0';
- }
- else
- {
- strcpy(path[c]->AreaDesc,test);
- result = strlen(wholeline);
- i = strlen(path[c]->AreaDesc);
- strncpy(path[c]->FilePath,wholeline,(result - i));
- path[c]->FilePath[(result - i)] = '\0';
- }
- c++; start++;
- }
- fclose(fp);
- message("Working...");
- return(1);
- }
-
- /*------------------------------------------------------------------------------*/
-
- void print_atcolor(int x, int y, int attr, unsigned char *line)
- {
- /*const long vmode = 0x00000449;*/
- int i = 0;
- int far *video_base;
- if((cga) || (ega) || (vga) || (mcga))
- video_base = (int far *)0xb8000000;
- else video_base = (int far *)0xb0000000;
- while (*(line + i))
- *(video_base + (x * 80) + y++) = *(line + i++) | (attr<<8);
- }
-
- /*------------------------------------------------------------------------------*/
-
- void files(int t)
- {
- char str[10];
- sprintf(str,"%d",t);
- print_atcolor(22,71,B_BLUE+F_YELLOW,str);
- }
-
- /*------------------------------------------------------------------------------*/
-
- void areap(char *str)
- {
- bios_scroll_up(1, 9, 2, 19, 77);
- print_atcolor(19,3,B_BLACK+F_LRED,str);
- }
-
- /*------------------------------------------------------------------------------*/
-
- void aread(char *str)
- {
- bios_scroll_up(1, 2, 2, 6, 77);
- print_atcolor(6,3,B_BLACK+F_LCYAN,str);
- }
-
- /*------------------------------------------------------------------------------*/
-
- void message(char *str)
- {
- print_atcolor(22,18,B_BLUE+F_WHITE,"║ ");
- print_atcolor(22,22,B_BLUE+F_YELLOW,str);
- }
-
- /*------------------------------------------------------------------------------*/
-
- void mainscreen()
- {
- int x;
-
- print_atcolor( 0,0,B_BLUE+F_WHITE,"╔═════════════════════════ FILELIST by Erik H. VanRiper ══════════════════════╗");
- for(x = 1; x < 23; x++)
- print_atcolor(x ,0,B_BLUE+F_WHITE,"║ ║");
- print_atcolor(23,0,B_BLUE+F_WHITE,"╚══════════════════════════════════════════════════════════════════════════════╝");
- print_atcolor(21,66,B_BLUE+F_WHITE,"╦═ # Files ═╣");
- print_atcolor(22,66,B_BLUE+F_WHITE,"║ ║");
- print_atcolor(23,66,B_BLUE+F_WHITE,"╚════════════╝");
- print_atcolor(21,0,B_BLUE+F_WHITE,"╠══ Total Bytes ══╦");
- print_atcolor(22,0,B_BLUE+F_WHITE,"║ ║");
- print_atcolor(23,0,B_BLUE+F_WHITE,"╚═════════════════╝");
- print_atcolor(21,18,B_BLUE+F_WHITE,"╦═══════════════════ Messages ══════════════════╦");
- print_atcolor(23,18,B_BLUE+F_WHITE,"╩═══════════════════════════════════════════════╩");
- print_atcolor( 8,1,B_BLACK+F_WHITE,"╔═══════════════════════════════ Area Processing ════════════════════════════╗");
- for(x = 9; x < 20; x++)
- print_atcolor(x ,1,B_BLACK+F_WHITE,"║ ║");
- print_atcolor(20,1,B_BLACK+F_WHITE,"╚════════════════════════════════════════════════════════════════════════════╝");
- print_atcolor( 1,1,B_BLACK+F_WHITE,"╔═══════════════════════════════ Area Directory ═════════════════════════════╗");
- for(x = 2; x < 7; x++)
- print_atcolor(x ,1,B_BLACK+F_WHITE,"║ ║");
- print_atcolor(7 ,1,B_BLACK+F_WHITE,"╚════════════════════════════════════════════════════════════════════════════╝");
- }
-
- /*==============================================================================*/
-
- /* The following bios_*() funtions were taken from the August 1991 edition of
- ** the C Users Journal<tm> and have the following copyright notice:
- **
- ** IBM bios scrren control package
- ** Copyright Dave Newman 1991
- ** Permission to use these routines for any reason is granted as long as this
- ** copyright notice is included.
- */
-
- /*------------------------------------------------------------------------------*/
-
- void bios_open()
- {
- union REGS regs;
-
- /* determine the display mode */
- regs.x.ax = 0x0f00;
- int86(0x10,®s,®s);
- cur_mode = regs.h.al;
- cur_page = regs.h.bh;
- /*num_cols = regs.h.ah;*/
-
- none = mono = herc = cga = ega = vga = mcga = color_disp = b_w = 0;
- vtest();
- }
-
- /*------------------------------------------------------------------------------*/
-
- /* video adapter type */
- void vtest()
- {
- union REGS regs;
- unsigned char hold_a_byte;
- int i;
-
- regs.h.ah = 0x1a;
- regs.h.al = 0;
- int86(0x10,®s,®s);
-
- if(regs.h.al == 0x1a)
- {
- if(regs.h.bl < 0x0a) vga = 1;
- else mcga = 1;
- color_disp = 1;
- return;
- }
-
- regs.h.ah = 0x12;
- regs.h.bl = 0x10;
- int86(0x10,®s,®s);
- if(regs.h.bl != 0x10)
- {
- ega = 1;
- if(regs.h.bh == 0) color_disp = 1;
- else b_w = 1;
- return;
- }
-
- bios_mode();
-
- if(cur_mode != 7)
- {
- outp(0x3d4,0x0f);
- hold_a_byte = inp(0x3d5);
- outp(0x3d5,0x63);
- for(i = 0; i < 100; i++);
- if(inp(0x3d5) == 0x63)
- {
- outp(0x3d5,hold_a_byte);
- cga = 1;
- color_disp = 1;
- return;
- }
- else
- {
- outp(0x3d5,hold_a_byte);
- none = 1;
- color_disp = 1;
- return;
- }
- }
-
- outp(0x3b4,0x0f);
- hold_a_byte = inp(0x3b5);
- outp(0x3b5,0x63);
- for(i = 0; i < 100; i++);
- if(inp(0x3b5) == 0x63)
- {
- outp(0x3b5,hold_a_byte);
- none = 1;
- b_w = 1;
- return;
- }
- outp(0x3b5,hold_a_byte);
- hold_a_byte = inp(0x3ba);
- hold_a_byte &= 0x80;
- for(i = 0; i < 1000; i++)
- {
- if(inp(0x3ba) & 0x80 != hold_a_byte)
- {
- herc = 1;
- break;
- }
- }
- if(!herc)
- {
- mono = 1;
- b_w = 1;
- return;
- }
- hold_a_byte = inp(0x3ba);
- switch(hold_a_byte)
- {
- case 0x50: color_disp = 1; break;
- case 0x00: b_w = 1; break;
- }
- }
-
- /*------------------------------------------------------------------------------*/
-
- int bios_mode()
- {
- union REGS regs;
- regs.h.ah = 15;
- int86(0x10,®s,®s);
- cur_mode = regs.h.al;
- return(regs.h.al);
- }
-
-
- /*------------------------------------------------------------------------------*/
-
- void bios_scroll_up(int count, int sr, int sc, int er, int ec)
- {
- union REGS regs;
- regs.h.al = count;
- regs.h.ch = sr;
- regs.h.cl = sc;
- regs.h.dh = er;
- regs.h.dl = ec;
- regs.h.bh = cur_attr;
- regs.h.ah = 6;
- int86(0x10,®s,®s);
- }
-
- /*------------------------------------------------------------------------------*/
-
- /* scroll active page dn. good to clear entire screen */
- void bios_scroll_dn(int count, int sr, int sc, int er, int ec)
- {
- union REGS regs;
- regs.h.al = count;
- regs.h.ch = sr;
- regs.h.cl = sc;
- regs.h.dh = er;
- regs.h.dl = ec;
- regs.h.bh = cur_attr;
- regs.h.ah = 7;
- int86(0x10,®s,®s);
- }
-
-
- /*------------------------------------------------------------------------------*/
-
- void bios_move(int row, int col)
- {
- union REGS regs;
-
- regs.h.dh = row;
- regs.h.dl = col;
- regs.h.ah = 2;
- regs.h.bh = cur_page;
- int86(0x10,®s,®s);
- /*cur_row = row;
- cur_col = col;*/
- }
-